package com.artpri.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.artpri.model.CategoryJoinGroup;
import com.artpri.model.GoodsCategory;
import com.artpri.service.GoodsCategoryService;

/**
 * @author ZhangSi
 */
public class GoodsCategoryServiceImpl extends BaseService implements
		GoodsCategoryService {

	@Override
	@Transactional(readOnly=true)
	public GoodsCategory getTopCategory(int gcId) {
		boolean isTop = false;
		
		int id = gcId;
		GoodsCategory goodsCategory = null;
		
		while (!isTop) {
			goodsCategory = getGoodsCategoryDao().get(GoodsCategory.class, id);
			if (goodsCategory.getCategoryId() == 0) {
				isTop = true;
			}else {
				id = goodsCategory.getCategoryId();
			}
		}
		
		return goodsCategory;
	}

	@Override
	@Transactional(readOnly=true)
	public List<GoodsCategory> getCategoryByGroup(Integer gcgId) {
		return getGoodsCategoryDao().getCategoryByGroup(gcgId);
	}

	@Override
	@Transactional(readOnly=true)
	public CategoryJoinGroup getGroupByCategory(Integer gcId) {
		return getCategoryJoinGroupDao().getGroupByCategroy(gcId);
	}

}
